<template>
	<view class="work-container">
		<!-- 轮播图 -->
		<!-- <u-swiper :list="list2" keyName="image" showTitle :autoplay="false" circular></u-swiper> -->
		<!-- 宫格组件 -->
		<uni-section title="系统管理" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false">
				<uni-grid-item v-show="RoleId == 2 || RoleId == 1|| RoleId == 3|| RoleId == 4|| RoleId == 5">
					<!-- <uni-badge text="1"></uni-badge> -->
					<view class="grid-item-box" @click="handToCustoms">
						<uni-icons type="person-filled" size="30"></uni-icons>
						<text class="text">我的报单</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 3 || RoleId == 1 || RoleId == 5">
					<view class="grid-item-box" @click="handToWorkOeder">
						<uni-icons type="staff-filled" size="30"></uni-icons>
						<text class="text">我的待办</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 4 || RoleId == 1">
					<view class="grid-item-box" @click="handToWorkTask">
						<uni-icons type="color" size="30"></uni-icons>
						<text class="text">工单任务</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4">
					<view class="grid-item-box" @click="handToGDsupervise">
						<uni-icons type="settings-filled" size="30"></uni-icons>
						<text class="text">工单监管</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4">
					<view class="grid-item-box" @click="handToInspectionPlan">
						<uni-icons type="heart-filled" size="30"></uni-icons>
						<text class="text">巡检计划</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4|| RoleId == 3|| RoleId == 5">
					<view class="grid-item-box" @click="handToInspection">
						<uni-icons type="bars" size="30"></uni-icons>
						<text class="text">巡检任务</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4|| RoleId == 3|| RoleId == 5">
					<view class="grid-item-box" @click="handToMaintenancePlan">
						<uni-icons type="gear-filled" size="30"></uni-icons>
						<text class="text">保养计划</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4|| RoleId == 3|| RoleId == 5">
					<view class="grid-item-box" @click="handToNowAlarm">
						<uni-icons type="chat-filled" size="30"></uni-icons>
						<text class="text">报警情况</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-show="RoleId == 1 || RoleId == 4|| RoleId == 3|| RoleId == 5|| RoleId == 2">
					<view class="grid-item-box" @click="handToEquipmentArchives">
						<uni-icons type="wallet-filled" size="30"></uni-icons>
						<text class="text">设备档案</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<uni-badge class="uni-badge-left-margin" :text="total" absolute="rightTop" :offset="[21, 0]"
						size="small">
						<!-- <view class="box"><text class="box-text">右上</text></view> -->
					</uni-badge>
					<view class="grid-item-box" @click="handToNotice">
						<uni-icons type="chat-filled" size="30"></uni-icons>
						<text class="text">通知公告</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
	</view>
</template>

<script>
	import {
		getNoticeList
	} from '@/api/system/user.js';
	import store from '@/store/index.js';
	export default {
		data() {
			return {
				total: 0,
				current: 0,
				list2: [{
						image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
						title: '昨夜星辰昨夜风，画楼西畔桂堂东'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
						title: '身无彩凤双飞翼，心有灵犀一点通'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
						title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
					}
				],
				RoleId: ''
			};
		},
		onLoad() {
			try {
				this.RoleId = uni.getStorageSync('roleId');
				if (this.RoleId) {
					console.log(this.RoleId);
				}
			} catch (e) {
				// error
			}
		},
		onShow() {
			getNoticeList("1", "10000").then(res => {
				var count = 0;
				// this.total = res.total;
				res.rows.map(item => { 
					if (this.$store.getters.userId != 1) {
						if (item.sysUserNotice.isRead == 0) {
							count++;
						}
					}
				})
				this.total = count;
			})
			uni.$on('total', (data) => {
				this.total = data;
			});
		},
		methods: {
			clickBannerItem(item) {
				console.info(item);
			},
			changeSwiper(e) {
				this.current = e.detail.current;
			},
			changeGrid(e) {
				console.log(e);
			},
			handToNotice() {
				this.$tab.navigateTo('/pages/work/worknotice/index');
			},
			handToCustoms() {
				this.$tab.navigateTo('/pages/work/CustomsDeclaration/index');
			},
			handToWorkOeder() {
				this.$tab.navigateTo('/pages/work/WorkOeder/index');
			},
			//工单任务
			handToWorkTask() {
				this.$tab.navigateTo('/pages/work/WorkTask/index');
			},
			//工单监管
			handToGDsupervise() {
				this.$tab.navigateTo('/pages/work/GDsupervise/index');
			},
			handToInspectionPlan() {
				this.$tab.navigateTo('/pages/work/InspectionPlan/index');
			},
			handToInspection() {
				this.$tab.navigateTo('/pages/work/Inspection/index');
			},
			handToMaintenancePlan() {
				this.$tab.navigateTo('/pages/work/MaintenancePlan/index');
			},
			handToNowAlarm() {
				this.$tab.navigateTo('/pages/work/NowAlarm/index');
			},
			//跳转设备档案
			handToEquipmentArchives() {
				this.$tab.navigateTo('/pages/work/EquipmentArchives/index');
			}
		}
	};
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}

	.uni-badge {
		position: absolute;
		right: 10px;
		top: 7px;
	}
</style>